using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using PraxisRent.Entities;

namespace PraxisRent.Repository.Mapping
{
    public class CREDITOMap : EntityTypeConfiguration<CREDITO>
    {
        public CREDITOMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Id)
                .IsRequired()
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(t => t.CodigoAlquiler)
                .IsOptional();

            this.Property(t => t.num_pagos)
                .IsOptional();

            this.Property(t => t.Cancelado)
                .IsOptional();

            // Table & Column Mappings
            this.ToTable("CREDITO");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.FechaEmision).HasColumnName("FechaEmision");
            this.Property(t => t.FechaVencimiento).HasColumnName("FechaVencimiento");
            this.Property(t => t.Cancelado).HasColumnName("Cancelado");
            this.Property(t => t.CodigoAlquiler).HasColumnName("CodigoAlquiler");
            this.Property(t => t.Total).HasColumnName("Total");
            this.Property(t => t.num_pagos).HasColumnName("NumPagos");

            // Relationships
            this.HasOptional(t => t.ALQUILER)
                .WithMany(t => t.CREDITOs)
                .HasForeignKey(d => d.CodigoAlquiler);
        }
    }
}
